var Md5 = require('../../utils/md5.js');
var timeSecond = Math.floor(Date.now() * 0.001);  //获取时间戳: 
var SignInfoData = Md5.hexMD5(timeSecond + 'nativetalk')//md5加密;
const app = getApp();
var httpNativetalk = app.globalData.httpNativetalk;
var httpWeike = app.globalData.httpWeike;
var httpFile = 'http://file.waijiaojun.com/';
var PageNum = 1, allClassArr = [], classDataTotalPage;
Page({
  data: {
    httpNativetalkFile: 'http://file.waijiaojun.com/',
    imgUrl: 'http://file.waijiaojun.com/waijiaojun/icon',
  },
  onShow: function (e) {
    wx.showShareMenu({
      withShareTicket: true,
    })
  },
  onLoad: function (e) {
    var that = this;
    //顶部分类数据请求
    wx.request({
      url: httpNativetalk + '/app/11/live/his/type',
      data: {},
      header: {//请求头
        "Timestamp": timeSecond,
        "SignInfo": SignInfoData,
        "content-Type": "application/json",
        "client_type": "3",
        "version": 15,
        "token": '',
      },
      method: 'POST',
      success: function (res) {
        var systemClassTypeArrOne = res.data.obj.live_type.slice(0, 5)
        var systemClassTypeArrTwo = res.data.obj.live_type.slice(5, 10)
        that.setData({
          systemClassTypeOneImg: systemClassTypeArrOne,
          systemClassTypeTwoImg: systemClassTypeArrTwo,
        })
      },
      fail: function (res) { },
      complete: function (res) { },
    })
    that.allClassDataFun(PageNum);

  },
  //课程数据请求
  allClassDataFun: function (PageNum) {
    var that = this;
    wx.request({
      url: httpWeike + '/v4.2/student/find/weike',
      data: {
        "currentPage": PageNum,
        "pageSize": "10",
      },
      header: {//请求头
        "Timestamp": timeSecond,
        "SignInfo": SignInfoData,
        "content-Type": "application/json",
        "client_type": "3",
        "version": 15,
        "token": '',
      },
      method: 'POST',
      success: function (res) {
        // console.log(res);
        classDataTotalPage = res.data.obj.totalPage;
        allClassArr.push(res.data.obj.data)
        that.setData({
          allClassList: res.data.obj.data,
          allClassArr: allClassArr,
        })
      },
      fail: function (res) { },
      complete: function (res) { },
    })

  },
  //触底加载更多
  onReachBottom: function () {
    if (PageNum < classDataTotalPage) {
      PageNum++;
      this.allClassDataFun(PageNum);
    }
  },
  //顶部分类按钮
  systemClassType: function (e) {
    var dictIds = e.currentTarget.dataset.idx;
    console.log(dictIds)
    wx.navigateTo({
      url: '/pages/systemClassType/systemClassType?dicId=' + dictIds
    });
  },
  //点击进入课程详情函数
  systemClassDetailFun: function (e) {
    var weikeIds = e.currentTarget.dataset.weikeid;
    wx.navigateTo({
      url: '/pages/systemClass/systemClass?weikeId=' + weikeIds,
    })
  },
  //成为会员页面跳转
  becomeVipFun: function (e) {
    wx.navigateTo({
      url: '/pages/becomeVIP/becomeVIP',
    })
  }
})